package com.kifas.service.dataaccess;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kifas.entity.SalesEntity;

@Repository
public class SalesDao {

	@Autowired
	private SessionFactory sessionFactory;

	private final static String ALL_SALES = "from SalesEntity ";
	private final static String SALES_BY_ID = ALL_SALES
			+ "where idSales = :idSales ";

	@SuppressWarnings("unchecked")
	public List<SalesEntity> getSales() {
		return sessionFactory.getCurrentSession().createQuery(ALL_SALES).list();
	}

	public SalesEntity getSalesById(Long id) {
		return (SalesEntity) sessionFactory.getCurrentSession()
				.createQuery(SALES_BY_ID).setLong("idSales", id).uniqueResult();
	}

	public void insert(SalesEntity sales) throws Exception {
		sessionFactory.getCurrentSession().save(sales);
	}
	
	public void update(SalesEntity sales) throws Exception {
		sessionFactory.getCurrentSession().update(sales);
	}

}
